function levelAndType() {
    var level = $("#levels").val();
    var type = $("#types").val();
    var tabNode = document.getElementById("mbTable");
    var x = tabNode.rows.length;
    //将所有的都赋值为选中的
    for (var i = 1; i < x; i++) {
        $("#level" + i).val(level);
        $("#type" + i).val(type);
    }
}

//初始化表
var tables = $("#mbTable");
var tabsize = document.getElementById("mbTable");
for (var x = 1; x < 14; x++) {
    var shang = '';
    var xia = '';
    if (x != 1) {
        shang = '↑';
    }
    if (x != 13) {
        xia = '↓';
    }
    var test = '';
    if (x == 1) {
        test = 'GO';
    } else if (x == 2) {
        test = 'GO2';
    }
    else if (x == 3) {
        test = '检图';
    } else if (x == 4) {
        test = '铸造';
    } else if (x == 5) {
        test = '加工';
    } else if (x == 6) {
        test = 'T1';
    } else if (x == 7) {
        test = 'T2';
    } else if (x == 8) {
        test = 'T3';
    } else if (x == 9) {
        test = '出货';
    } else if (x == 10) {
        test = 'LT1';
    } else if (x == 11) {
        test = 'LT2';
    } else if (x == 12) {
        test = 'LT3';
    } else if (x == 13) {
        test = 'LT交易';
    }
    tables.append('<tr id="shan' + x + '"> <td><input name="sortNum' + x + '" id="sortNum' + x + '" value="' + x + '" type="hidden"><b id="sequence' + x + '"> ' + x + '</b>  </td> <th><input type="text" class="form-control" name="code' + x + '"value="' + test + '" id="code' + x + '" /></th> <th><input type="text" class="form-control" name="name' + x + '" id="name' + x + '" /></th> <th><input type="text" class="form-control" name="defTime' + x + '" value="0" id="defTime' + x + '" onkeyup="value=value.replace(/[^\\d.]/g,\'\')" onblur="value=value.replace(/[^\\d.]/g,\'\')" /></th>  <th><select class="form-control input-sm mb15" name="defTimeUnit' + x + '" id="defTimeUnit' + x + '">  <option value="天">天</option>  <option value="分">分</option><option value="秒">秒</option><option value="小时">小时</option><option value="月">月</option> <option value="年">年</option>  </select> </th><input type="hidden" class="form-control" value="A" name="level' + x + '" id="level' + x + '"/> <input type="hidden" class="form-control" value="1" name="type' + x + '" id="type' + x + '"/> <th><a id="shang' + x + '" style="cursor:pointer;" onclick="shangyi(' + x + ')">' + shang + '</a></th> <th><a onclick="xiayi(' + x + ')" style="cursor:pointer;"><b id="xiaId' + x + '">' + xia + '</b></a></th> <th><a style="cursor:pointer;" onclick="delRow(this)">×</a></th></tr>');
}

function addMode() {
    var tables = $("#mbTable");
    var tabNode = document.getElementById("mbTable");
    var x = tabNode.rows.length;
    var shang = '';
    var xia = '';
    if (x != 1) {
        shang = '↑';
    }
    var xianum = x - 1;
    $("#xiaId" + xianum).text("↓");
    tables.append('<tr id="shan' + x + '"> <td><input name="sortNum' + x + '" id="sortNum' + x + '" value="' + x + '" type="hidden"><b id="sequence' + x + '"> ' + x + '</b>  </td> <th><input type="text" class="form-control" name="code' + x + '" id="code' + x + '" /></th> <th><input type="text" class="form-control" name="name' + x + '" id="name' + x + '" /></th> <th><input type="text" class="form-control" name="defTime' + x + '" value="0" id="defTime' + x + '" onkeyup="value=value.replace(/[^\\d.]/g,\'\')" onblur="value=value.replace(/[^\\d.]/g,\'\')" /></th>  <th><select class="form-control input-sm mb15" name="defTimeUnit' + x + '" id="defTimeUnit' + x + '">  <option value="天">天</option>  <option value="分">分</option><option value="秒">秒</option><option value="小时">小时</option><option value="月">月</option> <option value="年">年</option>  </select> </th> <input type="hidden" class="form-control" value="A" name="level' + x + '" id="level' + x + '"/>  <input type="hidden" class="form-control" value="1" name="type' + x + '" id="type' + x + '"/> <th><a id="shang' + x + '" style="cursor:pointer;" onclick="shangyi(' + x + ')">' + shang + '</a></th> <th><a onclick="xiayi(' + x + ')" style="cursor:pointer;"><b id="xiaId' + x + '">' + xia + '</b></a></th> <th><a style="cursor:pointer;" onclick="delRow(this)">×</a></th></tr>');
}

function xiayi(x) {
    //下移动
    var code = $("#code" + x).val();
    var name = $("#name" + x).val();
    var defTime = $("#defTime" + x).val();
    var defTimeUnit = $("#defTimeUnit" + x).val();
    var level = $("#level" + x).val();//难易度
    var type = $("#type" + x).val();//type

    var sele = document.getElementById("defTimeUnit" + x);
    var selelevel = document.getElementById("level" + x);
    var seletype = document.getElementById("type" + x);

    var index = x + 1;
    var upcode = $("#code" + index).val();
    var upname = $("#name" + index).val();
    var updefTime = $("#defTime" + index).val();
    var uplevel = $("#level" + index).val();//难易度
    var uptype = $("#type" + index).val();//type

    var updefTimeUnit = $("#defTimeUnit" + index).val();
    var upsele = document.getElementById("defTimeUnit" + index);
    var upselelevel = document.getElementById("level" + index);
    var upseletype = document.getElementById("type" + index);

    $("#code" + x).val(upcode);
    $("#name" + x).val(upname);
    $("#defTime" + x).val(updefTime);
    for (i = 0; i < sele.length; i++) {//给select赋值
        if (updefTimeUnit == sele.options[i].text) {
            sele.selectedIndex = i;
            break;
        }
    }
    for (i = 0; i < selelevel.length; i++) {//给select赋值
        if (uplevel == selelevel.options[i].text) {
            selelevel.selectedIndex = i;
            break;
        }
    }
    for (i = 0; i < seletype.length; i++) {//给select赋值
        if (uptype == seletype.options[i].text) {
            seletype.selectedIndex = i;
            break;
        }
    }

    $("#code" + index).val(code);
    $("#name" + index).val(name);
    $("#defTime" + index).val(defTime);
    for (i = 0; i < upsele.length; i++) {//给select赋值
        if (defTimeUnit == upsele.options[i].text) {
            upsele.selectedIndex = i;
            break;
        }
    }
    for (i = 0; i < upselelevel.length; i++) {//给select赋值
        if (level == upselelevel.options[i].text) {
            upselelevel.selectedIndex = i;
            break;
        }
    }
    for (i = 0; i < upseletype.length; i++) {//给select赋值
        if (type == upseletype.options[i].text) {
            upseletype.selectedIndex = i;
            break;
        }
    }
}

function shangyi(x) {
    var code = $("#code" + x).val();
    var name = $("#name" + x).val();
    var defTime = $("#defTime" + x).val();
    var defTimeUnit = $("#defTimeUnit" + x).val();
    var level = $("#level" + x).val();//难易度
    var type = $("#type" + x).val();//type

    var sele = document.getElementById("defTimeUnit" + x);
    var selelevel = document.getElementById("level" + x);
    var seletype = document.getElementById("type" + x);

    var index = x - 1;
    var upcode = $("#code" + index).val();
    var upname = $("#name" + index).val();
    var updefTime = $("#defTime" + index).val();
    var uplevel = $("#level" + index).val();//难易度
    var uptype = $("#type" + index).val();//type

    var updefTimeUnit = $("#defTimeUnit" + index).val();
    var upsele = document.getElementById("defTimeUnit" + index);
    var upselelevel = document.getElementById("level" + index);
    var upseletype = document.getElementById("type" + index);

    $("#code" + x).val(upcode);
    $("#name" + x).val(upname);
    $("#defTime" + x).val(updefTime);
    for (i = 0; i < sele.length; i++) {//给select赋值
        if (updefTimeUnit == sele.options[i].text) {
            sele.selectedIndex = i;
            break;
        }
    }
    for (i = 0; i < selelevel.length; i++) {//给select赋值
        if (uplevel == selelevel.options[i].text) {
            selelevel.selectedIndex = i;
            break;
        }
    }
    for (i = 0; i < seletype.length; i++) {//给select赋值
        if (uptype == seletype.options[i].text) {
            seletype.selectedIndex = i;
            break;
        }
    }

    $("#code" + index).val(code);
    $("#name" + index).val(name);
    $("#defTime" + index).val(defTime);
    for (i = 0; i < upsele.length; i++) {//给select赋值
        if (defTimeUnit == upsele.options[i].text) {
            upsele.selectedIndex = i;
            break;
        }
    }
    for (i = 0; i < upselelevel.length; i++) {//给select赋值
        if (level == upselelevel.options[i].text) {
            upselelevel.selectedIndex = i;
            break;
        }
    }
    for (i = 0; i < upseletype.length; i++) {//给select赋值
        if (type == upseletype.options[i].text) {
            upseletype.selectedIndex = i;
            break;
        }
    }
}